package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsAttributeMapper;
import com.qf.pojo.DtsGoodsAttribute;
import com.qf.service.DtsGoodsAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DtsGoodsAttributeServiceImpl implements DtsGoodsAttributeService {
    @Autowired
    DtsGoodsAttributeMapper attributeMapper;
    @Override
    public void updateAttributes(Integer id, DtsGoodsAttribute[] attributes) {
        //先根据商品id删除 属性记录
        LambdaQueryWrapper<DtsGoodsAttribute > qw = new LambdaQueryWrapper<>();
        qw.eq(DtsGoodsAttribute::getGoodsId, id);
        attributeMapper.delete(qw);

        //添加属性
        if(attributes != null && attributes.length > 0) {
            for (DtsGoodsAttribute attribute : attributes) {
                attribute.setAddTime(new Date());
                attribute.setUpdateTime(new Date());
                attribute.setGoodsId(id);
                attributeMapper.insert(attribute);
            }
        }
    }
}
